package baidu_review

import (
	"encoding/json"
	"fmt"
	"github.com/Baidu-AIP/golang-sdk/aip/censor"
)

type Review struct {
}

func NewReview() *Review {
	return &Review{}
}

func (r *Review) TestingString(str string) bool {
	client := censor.NewClient("KvxJKNxqhOxhRW4eFunZDN2z", "BD9SQDATquPFdBoJESuZU7DlIBgJupRZ")
	res := client.TextCensor(str)

	var resData map[string]interface{}

	err := json.Unmarshal([]byte(res), &resData)
	if err != nil {
		return false
	}
	//fmt.Println(resData)

	if resData["conclusion"] == "不合规" {
		fmt.Println("不合规")
		return false
	}
	return true
}

func (r *Review) TestingStringV2(image string, maps map[string]interface{}) bool {
	client := censor.NewClient("KvxJKNxqhOxhRW4eFunZDN2z", "BD9SQDATquPFdBoJESuZU7DlIBgJupRZ")
	res := client.ImgCensor(image, maps)

	var resData map[string]interface{}

	err := json.Unmarshal([]byte(res), &resData)
	if err != nil {
		return false
	}
	//fmt.Println(resData)

	if resData["conclusion"] == "不合规" {
		fmt.Println("不合规")
		return false
	}
	return true
}
